﻿@using System.Configuration
@using ThuySan.Bussiness
@model IEnumerable<ThuySan.Bussiness.Product>
@{
    ViewBag.Title = @ViewBag.Category.Name;
    Layout = "~/Views/Shared/_Layout.cshtml";
    int count, pageSize;
    int.TryParse(ViewBag.Count + "", out count);
    int.TryParse(ViewBag.PageSize + "", out pageSize);
}
@section Scripts
{
    <script language="javascript" type="text/javascript">
        function resetSearch() {
            var s = $('#selectPrductSort').val().split(':');
            window.location.href = '@Request.Url.AbsolutePath?type=' + s[0] + '&otype=' + s[1];
        }

        $(document).ready(function () {
            var type = '@Request.QueryString["type"]';
            var otype = '@Request.QueryString["otype"]';
            $('#selectPrductSort').val(type + ':' + otype);
            $('#nb_item').val('@Request.QueryString["n"]');
        });
    </script>
}
<div class="breadcrumb bordercolor">
    <div class="breadcrumb_inner">
        <a title="return to Home" href="/">Home</a> <span class="navigation-pipe">&gt;</span>
        @ViewBag.Category.Name
    </div>
</div>
<h1>
    @ViewBag.Category.Name<span class="category-product-count"> Có @count sản phẩm.</span>
</h1>
<p class="cat_desc bordercolor bgcolor">@ViewBag.Category.Description</p>
<div class="product_sort">
    <form action="@Request.Url.AbsolutePath"
          id="productsSortForm">
    <label for="selectPrductSort">
        Sắp xếp theo</label>
    <select id="selectPrductSort" onchange=" javascript:resetSearch(); ">
        <option selected="selected" value="position:asc">--</option>
        @*<option value="price:asc">Sắp xếp theo giá tăng dần</option>
        <option value="price:desc">Sắp xếp theo giá giảm dần</option>*@
        <option value="name:asc">Sắp xếp theo tên: A đến Z</option>
        <option value="name:desc">Sắp xếp theo tên: Z đến A</option>
        @*<option value="status:desc">In stock</option>*@
    </select>
    </form>
</div>
@*List products*@
@functions{

    private bool IsNew(DateTime? lastModified)
    {
        return (DateTime.Now - (lastModified ?? DateTime.Now)).TotalDays <= int.Parse(ConfigurationManager.AppSettings["NewProductTimeSpan"]);
    }

}
<ul id="product_list" class="bordercolor grid">
    @{
        int i=0;
        foreach (Product pro in Model)
        {
            i++;
            
        <li class="ajax_block_product bordercolor @(i%3==0?"product_list-3":"") "><a title="@pro.Description"
                                                      class="product_img_link" href="/@pro.GetUrl()">
            <img alt="@pro.AvatarImage" src="@Html.UploadPath("Products")140x140_@(pro.AvatarImage)" onError=" this.src = '/Content/images/140x140_error.png'; "/></a>
            <div class="center_block">
                <div class="product_flags">
                    <span class="new">@(IsNew(pro.LastModified)
                                                ? "Mới"
                                                : "")</span> <span class="availability bordercolor">@(pro.Status ?? false
                                                                                                              ? "Còn hàng"
                                                                                                              : "Hết hàng")</span>
                </div>
                <h3>
                    <a title="@pro.Description" href="/@pro.GetUrl()" class="product_link">@Html.Truncate(pro.Name,60)</a></h3>
                <p class="product_desc">
                    <a title="@pro.Description" href="/@pro.GetUrl()"
                       class="product_descr">@pro.Description</a></p>
                <div style="clear: both">
                </div>
            </div>
            <div class="right_block bordercolor">
                @* @{
        if (pro.IsReduced == true)
        {
                    <span class="discount">Giảm giá!</span>
                    <span class="price">@string.Format("{0:c0}", pro.PromotionalPrice)</span>
        }
        else
        {
                    <span class="price">@string.Format("{0:c0}", pro.Price)</span>
        }
                }*@ <a title="View" href="/@pro.GetUrl()" class="exclusive ajax_add_to_cart_button">
                    Chi tiết</a>
            </div>
            <div class="clear">
            </div>
        </li>
        }
    }
</ul>
<!-- Pagination -->
<div id="pagination">
    <ul class="pagination">
        @Html.Raw(Html.Pager(5, pageSize, count, Request.Url.AbsolutePath, Request.QueryString, "page"))
    </ul>
    <form method="get" action="@Request.Url.AbsolutePath" id="pagination_form">
    @Html.Hidden("type")
    @Html.Hidden("otype")
    @Html.Hidden("page")
    <a href="javascript:document.getElementById('pagination_form').submit();" class="button_mini">
        Ok</a>
    <label for="nb_item">
        items:</label>
    <select id="nb_item" name="n">
        <option value="9">9</option>
        <option value="12">12</option>
        <option value="24">24</option>
        <option value="36">36</option>
    </select>
    </form>
</div>
<!-- /Pagination -->
